<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <svg class='chart'></svg>
    <script src="d3.v4.min.js"></script>
    <script>
 var margin = {top: 20, right: 30, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

        const x = d3.scalePoint()
    .range([0, width])
    .padding(0.4)

    const y = d3.scaleLinear()
    .range([height, 0]);//

    const xAxis = d3.axisBottom()
        .scale(x)

        const yAxis = d3.axisLeft()
        .scale(y)

        const chart = d3.select(".chart")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
    
d3.csv("./data/data.csv", function(error, data) {//换tsv文件位置//y

  // console.log(data);

  x.domain(data.map(function(d) { return d.name; }));
  y.domain([0, d3.max(data, function(d) { return d.value; })]);//

  chart.append("g")//换一个字母？//不行
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height+ ")")
      .call(xAxis);

  chart.append("g")
      .attr("class", "y axis")
      .call(yAxis);

  chart.selectAll(".bar")
      .data(data)
    .enter().append("rect")
      .attr("class", "bar")
      .attr("x", function(d) { return x(d.name); })
      .attr("y", function(d) { return y(d.value); })
      .attr("height", function(d) { return height - y(d.value); })
      .attr("width", 26);
});



    </script>
    
</body>
<style>

    .bar {
      fill: steelblue;
    }
    
    .axis text {
      font: 10px sans-serif;
    }
    
    .axis path,
    .axis line {
      fill: none;
      stroke: #000;
      shape-rendering: crispEdges;
    }
    
    .x.axis path {
      display: none;
    }
    
    </style>

</html>
